var t = getApp();

Page({
    data: {
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        listData: [],
        networkLoading: !1,
        banner: [],
        buttons: [],
        category: [],
        searchText: "",
        activeName: 0,
        tabsShow: !1
    },
    onLoad: function(t) {
        this.getData(), this.getCircleSet();
    },
    onReady: function() {},
    tapUrl: function(t) {
        var a = t.currentTarget.dataset.url;
        if ("" == a) return !1;
        try {
            wx.navigateTo({
                url: a
            });
        } catch (t) {
            console.log(t);
        }
    },
    onShow: function() {},
    gotoSearch: function() {
        wx.navigateTo({
            url: "/packageH/circleCommunity/circleSearch/circleSearch"
        });
    },
    getData: function() {
        var a = this, e = t.getNetAddresss("plugin.circle.frontend.circle.index");
        t._postNetWork({
            url: e,
            data: {},
            success: function(e) {
                var i = e.data;
                if (1 != i.result) return t.tips(i.msg);
                a.data.total_page = i.data.list.last_page, a.data.total_page || (a.data.total_page = 0), 
                a.setData({
                    banner: i.data.banner,
                    buttons: i.data.button,
                    category: i.data.category,
                    listData: i.data.list.data,
                    networkLoading: !0,
                    tabsShow: !0
                });
            }
        });
    },
    changeCategory: function(t) {
        this.setData({
            activeName: t.detail.index
        }), this.getListData();
    },
    initData: function() {
        this.setData({
            page: 1,
            total_page: 0,
            isLoadMore: !0,
            networkLoading: !1
        });
    },
    getListData: function() {
        var a = this;
        this.initData();
        var e = this.data, i = e.activeName, o = e.category, n = {
            is_recommend: 0
        };
        0 == i ? n.is_recommend = 1 : n.category_id = o[i - 1].id;
        var r = t.getNetAddresss("plugin.circle.frontend.circle.get-circle-list");
        t._postNetWork({
            url: r,
            data: n,
            success: function(e) {
                var i = e.data;
                if (1 != i.result) return t.tips(i.msg);
                a.data.total_page = i.data.last_page, a.data.total_page || (a.data.total_page = 0), 
                a.setData({
                    listData: i.data.data,
                    networkLoading: !0
                });
            }
        });
    },
    getCircleSet: function() {
        var a = t.getNetAddresss("plugin.circle.frontend.circle.get-set");
        t._getNetWork({
            url: a,
            data: {},
            success: function(a) {
                var e = a.data;
                if (1 != e.result) return t.tips(e.msg);
                wx.setNavigationBarTitle({
                    title: e.data.plugin_name
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    _getMoreData: function() {
        var a = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page += 1;
            var e = this.data, i = e.activeName, o = e.category, n = {
                is_recommend: 0,
                page: this.data.page
            };
            0 == i ? n.is_recommend = 1 : n.category_id = o[i - 1].id;
            var r = t.getNetAddresss("plugin.circle.frontend.circle.get-circle-list");
            t._postNetWork({
                url: r,
                data: n,
                success: function(t) {
                    var e = t.data;
                    if (a.data.isLoadMore = !0, 1 === e.result) {
                        var i = a.data.listData.concat(e.data.data);
                        a.setData({
                            listData: i
                        });
                    } else a.data.page = a.data.page - 1, a.data.isLoadMore = !1;
                }
            });
        }
    },
    gotoCircleDetails: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageH/circleCommunity/circleDetails/circleDetails?circleId=" + a
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onShareTimeline: function() {},
    onShareAppMessage: function() {}
});